package service;


import domain.Products;
import tools.DBHelper;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ProductService {
    private String sql = "";

    public List<Products> findByAll(int pre,int post){
        sql = "select * from products limit ?,?";
        List<Map<String,Object>> data = DBHelper.query(sql,pre,post);
        List<Products> products = new ArrayList<>();

        for (Map<String,Object> row: data) {
            Products product = new Products(
                    Integer.parseInt(row.get("pid").toString())
                    ,row.get("pname").toString()
                    ,Integer.parseInt(row.get("pnum").toString())
                    ,Integer.parseInt(row.get("ptype").toString())
                    );
            products.add(product);
        }

        return products;
    }
    public int findCount(){
        int count=0;
        sql="select conut(*) from  products";

        return count;
    }
    }


